package com.ning.ems.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * @author Ning 242741154@qq.com
 * @date 2020/5/26 17:18
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public String serviceException(HttpServletResponse response, ServiceException e) {
        response.setStatus(e.status.value());
        return e.message;
    }
}
